package com.qf.controller;

import com.qf.pojo.User;
import com.qf.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;



/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/6/9 19:16
 */
@Controller
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private HttpServletRequest request;

    Logger logger=Logger.getLogger(UserController.class);

    @RequestMapping("/list")
    public String userList(Model model){

        //可以在开发阶段使用打印debug信息
        logger.debug("=======这是debug信息===========");
        //日志中的数据需要收集, 供大数据分析使用, 那么可以正常打印info信息
        logger.info("=======这是info信息===========");
        //一般在try catch捕获到异常的时候, 打印error信息
        logger.error("=======这是error信息===========");
        //1. 调用service查询
     /*   List<User> userAll = userService.findUserAll();
        model.addAttribute("users", userAll);*/
        //2
        List<User> byNameAndSexAndBirthday = userService.findUserAll();
        Model users = model.addAttribute("users", byNameAndSexAndBirthday);

        //3. 指定页面位置
        return "user";

    }
}
